package org.infodavid.common.persistence;

import java.util.List;

import javax.persistence.PersistenceException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.infodavid.common.model.IOrganization;
import org.infodavid.common.persistence.impl.AbstractDataService;
import org.infodavid.common.reflect.InstantiationHelper;

/**
 * The Class OrganizationDataService.
 */
public abstract class OrganizationDataService extends AbstractDataService<IOrganization,Long> {

  /** The singleton. */
  private static final OrganizationDataService SINGLETON;

  /** The Constant log. */
  private static final Log LOGGER = LogFactory.getLog(OrganizationDataService.class);

  static {
    try {
      SINGLETON = InstantiationHelper.getInstance().newInstance(OrganizationDataService.class);
    }
    catch (final Exception e) {
      LOGGER.fatal("Can not instantiate the " + OrganizationDataService.class.getName(), e);

      throw new Error(e);
    }
  }

  /**
   * returns the singleton.
   * @return the singleton
   */
  public static OrganizationDataService getInstance() {
    return SINGLETON;
  }

  /**
   * Instantiates a new service.
   */
  protected OrganizationDataService() {
    super();
  }

  /**
   * Do find by name.
   * @param session the session
   * @param value the value
   * @param entities the entities
   * @param parameters the parameters
   * @return the organizations
   * @throws PersistenceException the persistence exception
   */
  public abstract long findByName(PersistenceSession session, String value,
      List<IOrganization> entities, List<IQueryParameter> parameters) throws PersistenceException;
}
